package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Moneytransaction;
import com.restaurant.service.MoneytransactionService;

public class MoneytransactionServiceImpl implements MoneytransactionService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Moneytransaction addOrModify( Moneytransaction objMoneytransaction ) {
       return ( Moneytransaction ) hibernateTemplate.merge( objMoneytransaction );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Moneytransaction deleteRecord( Moneytransaction objMoneytransaction ) {
       hibernateTemplate.delete( objMoneytransaction );
       return objMoneytransaction;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Moneytransaction modifyRecord( Moneytransaction objMoneytransaction ) {
       return ( Moneytransaction ) hibernateTemplate.merge( objMoneytransaction );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Moneytransaction> loadAll() {
       return (List<Moneytransaction>)hibernateTemplate.findByNamedQuery( "Moneytransaction.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Moneytransaction loadByPrimaryKey( Long primaryKey ) {
       return (Moneytransaction) hibernateTemplate.get( Moneytransaction.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Moneytransaction deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Moneytransaction> loadByHql(String query) {
       return ( List<Moneytransaction> ) hibernateTemplate.find( query );
   }
}